package com.firsteapps.mobile.android.puzzle;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;

import com.firsteapps.mobile.android.puzzle.game.Helper;
import com.firsteapps.mobile.android.puzzle.util.Consts;
import com.firsteapps.mobile.android.puzzle.util.Utilities;

public class Options extends BaseActivity {

	private CheckBox musicSetting, soundSetting, vibrationSetting;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.options);

		musicSetting = (CheckBox) findViewById(R.id.music_setting);
		soundSetting = (CheckBox) findViewById(R.id.sound_setting);
		vibrationSetting = (CheckBox) findViewById(R.id.vibration_setting);

		boolean[] settings = getSettings();
		musicSetting.setChecked(settings[0]);
		soundSetting.setChecked(settings[1]);
		vibrationSetting.setChecked(settings[2]);

		findViewById(R.id.options_save).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Helper.doMessageDialog(Options.this, "Save Settings", "Are you sure you want to save changes?",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog, int which) {
								boolean mChecked, sChecked, vChecked;
								mChecked = musicSetting.isChecked();
								sChecked = soundSetting.isChecked();
								vChecked = vibrationSetting.isChecked();
								setSettings(mChecked, sChecked, vChecked);
								String[] settingsData = new String[] { "" + mChecked, "" + sChecked, "" + vChecked };
								Helper.savePuzzleData(Options.this, Consts.FILE_NAME_SETTINGS, settingsData);
								Utilities.startActivityWithAnimation(Options.this, Home.class);
							}
						}, true);
			}
		});
	}
}
